package zqservlet;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import zqdb.O_INFO;
import zqtools.DBUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@WebServlet(name = "zuServlet", urlPatterns = "/zu")
public class zuServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        HttpSession session = request.getSession();
        session.setAttribute("sessionOpid",  UUID.randomUUID().toString().replaceAll("-", "").toUpperCase(Locale.ROOT));

        Calendar calendar = new GregorianCalendar();
        calendar.add(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_MONTH, 0);

        //格式化时间
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //将时间转化成String类型
        String fDate = format.format(new Date());
        String sDate = format.format(calendar.getTime());
        //解析String为Date
        Date date1 = null;
        Date date2 = null;
        try {
            date1 = format.parse(sDate);
            date2 = format.parse(fDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //两日期相减，所得毫秒数 除以1000得秒 除以3600得小时 除24得天数得到两个日期的间隔
//        assert date1 != null;
//        assert date2 != null;
//        int day = (int) ((date1.getTime() - date2.getTime()) / (1000*3600*24));
//        if (day >= 3) {
            request.getRequestDispatcher("/index2.jsp").forward(request, response);
//        }
//        else{
//            request.getRequestDispatcher("/w_welcome3.jsp").forward(request, response);
//        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
